counter = 0;
max_percentage_distance = 1000;
metric = 1000;
distance_mat = [];
while metric > 0.003 && counter < 600
%while mean(abs(distance_percentage-1)) > 0.003 && counter < 600 && max(abs(distance_percentage-1))>0.1
sim_exports_wages_parallel
distance = total_income_vec - GDP_vec; 
distance_percentage = total_income_vec ./ GDP_vec;
average_dollar_distance = mean(abs(distance))
max_percentage_distance = max(abs(distance_percentage-1))
metric = mean(abs(distance_percentage-1))
distance_mat = [distance_mat; distance];
if average_dollar_distance > 1e8
    if counter < 40
    GDP_guesses = GDP_vec+0.5*(total_income_vec-GDP_vec);
    elseif counter < 80
    GDP_guesses = GDP_vec+0.1*(total_income_vec-GDP_vec);  
    elseif counter < 120
    GDP_guesses = GDP_vec+0.01*(total_income_vec-GDP_vec);  
    elseif counter < 160
    GDP_guesses = GDP_vec+0.005*(total_income_vec-GDP_vec);   
    else
    counter = 600;
    end
elseif average_dollar_distance > 5e7
    if counter < 40
    GDP_guesses = GDP_vec+0.1*(total_income_vec-GDP_vec); 
    elseif counter < 80
    GDP_guesses = GDP_vec+0.01*(total_income_vec-GDP_vec);   
    elseif counter < 200
    GDP_guesses = GDP_vec+0.005*(total_income_vec-GDP_vec);   
    else
    counter = 600;
    end
else 
    if counter < 200
    GDP_guesses = GDP_vec+0.005*(total_income_vec-GDP_vec);   
    else
    counter = 600;
    end
end
wage_guesses = GDP_guesses./L_vec;
wage_guess_mat = repmat(wage_guesses,n_varieties_ag,1);
wage_guess_mat_3D = repmat(wage_guess_mat,1,1,n_countries);
counter = counter+1
end
if counter > 599
    disp('DID NOT CONVERGE')
end